<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>
        
        //可视化 -> Java端
        var emp = {
             name : "张三",
             dept: {
                deptName:"教学部"
             }
        }

        //获取部门名称
        let deptName = emp.dept.deptName || "默认值";
        //链式获取,添加非空的校验问题(js本身就支持的)
        let deptName1 = emp || emp.dept || emp.dept.deptName || "默认值";
        //es6对链式的优化 
        //? 可以判断非空 null undefined '' 不继续向后获取 走 || 默认值
        let deptName2 = emp?.dept?.deptName || "默认值";


        let name = "xxx";
        //name != 空 进行某一项业务! name 由后端传递的!
        if(name =! null && name != undefined && name == ''){
            //某一项业务
        }
        // ()=>boolean=>true|false=> name=> boolean  非空 = true || 空(undefined null '') = false
        if(name){
            //某一项业务
        }

    </script>
    
</body>
</html>